/**
 * 
 */
package testcases;

import static org.junit.Assert.assertEquals;

import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;

import com.trentech.billcalc.FinanceManager;
import com.trentech.billcalc.event.StartLeaseEvent;
import com.trentech.billcalc.gui.*;
import com.trentech.billcalc.gui.BillCalcFrame.ResidentSelectionListener;
import com.trentech.billcalc.gui.EventEditor.CancelAction;



/**
 * @author marieputri
 *
 */
public class GUITest 
{
    
    public static void TestGUIComponents(FinanceManager fm) throws Exception
    {
        TestMessages();
        TestBillCalcFrame(fm);
        TestEventEditor(fm);
    }
    
    
    public static void TestMessages() {
        assertEquals("Gass Bill Unpaid Estimate",
                Messages.getUnpaidEstimate("Gass Bill"));
        assertEquals("Jessa owes the following:",
                Messages.getWhoOwesTheFollowing("Jessa"));
        assertEquals("Marie Putri owes Jessa the following:",
                Messages.getWhoOwesWho("Marie Putri", "Jessa"));
    }

    
    public static void TestBillCalcFrame(FinanceManager fm) {
        //FinanceManager fm = new FinanceManager();
        
        BillCalcFrame bcf = new BillCalcFrame(fm);
        
        ResidentSelectionListener rsl = bcf.new ResidentSelectionListener();
        JList residentList = new JList(fm.getResidents().toArray());
        rsl.valueChanged(new ListSelectionEvent(residentList, 0, 3, true));
    }


    public static void TestEventEditor(FinanceManager fm) throws Exception {
        UserFriendlinessManager um = new UserFriendlinessManager(
                new BillCalcFrame(fm));
        EventEditor ee = new EventEditor(fm, um);
        
        TestEventEditor_SetEvent(ee);
        TestEventEditor_CancelAction(ee);
        TestEventEditor_Other(ee);
    }


    public static void TestEventEditor_SetEvent(EventEditor ee) {
    	ee.setEvent(null, true);
    	ee.setEvent(EventData.ListStartLease.get(1), false);
        ee.saveEvent();
    }


    public static void TestEventEditor_Other(EventEditor ee) throws Exception {
        String moneyText = EventEditor.formatMoneyForDisplay(new Integer(123456));
        Integer moneyInt = EventEditor.parseMoneyForDisplay(moneyText);

        assertEquals(new Integer(123456), moneyInt);
    }


    public static void TestEventEditor_CancelAction(EventEditor ee) {
        CancelAction ca = ee.new CancelAction();
        ca.actionPerformed(null);
    }

}
